<?php

if (!isset($_SESSION))
    session_start();
require_once("dbclass.php");

class ItineraryDBclass {

    public $db;
    public $error = "&nbsp;";
    private $booking_data = array("idUser" => "", "itineraryId" => "");

    public function SetData($idUser, $itineraryId) {
        $this->booking_data["idUser"] = $idUser;
        $this->booking_data["itineraryId"] = $itineraryId;
    }

    public function connectToDb() {
        $this->db = new dbclass;
        $parameters = array("localhost", "test", "test");
        $this->db->connect($parameters)->select_db("eandb");
    }

    public function insertData() {
        if ($this->booking_data["idUser"] != "" && $this->booking_data["itineraryId"] != "") {

            $result = $this->db->query("INSERT INTO bookings SET idUser = '" . $this->booking_data["idUser"] . "',
                                                              itineraryId = '" . $this->booking_data["itineraryId"] . "'");
        }
    }

    public function getBookings($username) {
        $result = $this->db->query("SELECT email, itineraryId FROM users INNER JOIN bookings ON users.id = bookings.idUser where username='$username'")->fetch();
        return $result;
    }

    public function GetIdUser($username) {
        echo $username;
        $result = $this->db->query("SELECT id FROM users where username='$username'")->fetch();
        //print_r($result);
        return $result[0]['id'];
    }

}

?>
